package LeetCode刷题;

import java.util.Arrays;

/**
 * @program: Java_Study
 * @author: Xiaofan
 * @createTime: 2021-11-14 14:48
 * @description: Functions of this class is
 * 官方题解：
 * class Solution {
 *     public int singleNumber(int[] nums) {
 *         int ans = 0;
 *         for (int i = 0; i < 32; ++i) {
 *             int total = 0;
 *             for (int num: nums) {
 *                 total += ((num >> i) & 1);
 *             }
 *             if (total % 3 != 0) {
 *                 ans |= (1 << i);
 *             }
 *         }
 *         return ans;
 *     }
 * }
 **/
public class 只出现一次的数字II {
    public static void main(String[] args) {

    }
    public int singleNumber(int[] nums) {
        Arrays.sort(nums);
        int len=nums.length;
        for(int i=0;i<len-2;i++){
            if(i==0&&nums[i]!=nums[i+1]){
                return nums[0];
            }
            else if(nums[i]!=nums[i+1]&&nums[i]!=nums[i-1]){
                System.out.println(nums[i]+"-"+nums[i+1]);
                return nums[i];
            }
        }
        return nums[len-1];
    }
}